package com.ftg.learn.chapter01;

import java.util.Arrays;

/**
 * 冒泡排序
 *
 * @author lenovo
 * @version 1.0
 * @date 2023/5/20 16:11
 */

public class MaoPao {
    public static void bubble(int[] arr2){
        for (int j = 0; j < arr2.length - 1; j++) {
            for (int i = 0; i < arr2.length - 1-j; i++) {
                if (arr2[i] > arr2[i + 1]) {
                    arr2[i] = arr2[i] + arr2[i + 1];
                    arr2[i + 1] = arr2[i] - arr2[i + 1];
                    arr2[i] = arr2[i] - arr2[i + 1];
                }
            }
        }
    }

    /**
     * 选择排序
     * @param arr2
     */
    public static void choose(int[] arr2){
        //求几次
        for (int j = 0; j < arr2.length - 1; j++) {
            //计数器
            int maxVal = Integer.MIN_VALUE;
            int index = 0;
            for (int i = 0; i < arr2.length - j; i++) {
                if (maxVal < arr2[i]) {
                    maxVal = arr2[i];
                    index = i;

                }
            }
            int temp = arr2[index];
            arr2[index] = arr2[arr2.length - 1 - j];
            arr2[arr2.length - 1 - j] = temp;
        }

        System.out.println(Arrays.toString(arr2));
    }

    //排序

}
